package com.tianruan.dc.modules.sys.user.api;


import com.tianruan.dc.common.utils.response.VResponse;
import com.tianruan.dc.modules.sys.user.entity.dto.ConsultationDTO;
import com.tianruan.dc.modules.sys.user.entity.dto.TutorSolutionDTO;
import com.tianruan.dc.modules.sys.user.service.ITutorSolutionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/sys/consultation/solution")
@Slf4j

public class TutorSolutionController {

    @Autowired
    private ITutorSolutionService iTutorSolutionService;

    /**
     * 新增导师解答
     * @param tutorSolutionDTO
     * @return
     */
    @PostMapping("/add")
    //授权
    @PreAuthorize("hasAnyAuthority('sys:super:admin','sys:teacher')")
    public VResponse add(@Validated @RequestBody TutorSolutionDTO tutorSolutionDTO,
                         @RequestParam String id)
    {
        log.info("新增导师解答: {}",tutorSolutionDTO);
        iTutorSolutionService.add(tutorSolutionDTO, id);
        return VResponse.success("新增导师解答成功");
    }

    /**
     * 删除导师解答
     * @param tutorSolutionDTO
     * @return
     */
    @DeleteMapping("/delete")
    //授权
    @PreAuthorize("hasAnyAuthority('sys:super:admin','sys:teacher')")
    public VResponse delete(@RequestBody TutorSolutionDTO tutorSolutionDTO){
        log.info("删除导师解答: {}",tutorSolutionDTO);
        iTutorSolutionService.delete(tutorSolutionDTO);
        return VResponse.success("删除导师解答成功");
    }

    /**
     * 根据id查找导师解答
     * @param id
     * @return
     */
    @GetMapping("/solution{id}")
    //授权
    @PreAuthorize("hasAnyAuthority('sys:super:admin','sys:teacher','sys:student')")
    public VResponse getbyid(String id){
        log.info("根据id查询导师解答: {}",id);
        TutorSolutionDTO tutorSolutionDTO = iTutorSolutionService.getbyid(id);
        return VResponse.success(tutorSolutionDTO);
    }

    /**
     * 修改导师解答
     * @param tutorSolutionDTO
     * @return
     */
    @PutMapping("/update")
    //授权
    @PreAuthorize("hasAnyAuthority('sys:super:admin','sys:teacher')")
    public VResponse update(@RequestBody TutorSolutionDTO tutorSolutionDTO){
        log.info("修改导师解答: {}",tutorSolutionDTO);
        iTutorSolutionService.update(tutorSolutionDTO);
        return VResponse.success("修改导师解答成功");
    }

    /**
     * 根据咨询id查询该咨询下所有解答
     * @param id
     * @return
     */
    @GetMapping("/selectSolution{id}")
    //授权
    @PreAuthorize("hasAnyAuthority('sys:super:admin','sys:teacher','sys:student')")
    public VResponse<List<ConsultationDTO>> selectSolution(String id){
        log.info("根据咨询id查询该咨询下所有解答: {}",id);
        List<ConsultationDTO> getSolution = iTutorSolutionService.selectSolution(id);
        return VResponse.success(getSolution);
    }
}
